package com.bear.cmcc.NetTestHTTP.ui.view;


import com.bear.cmcc.NetTestHTTP.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 无数据提示控件
 * @author meizhen.xu
 *
 */
public class NorecordLayout extends LinearLayout {

	private LinearLayout mainLayout;
	private Button refreshButton;
	private TextView text;
	private Context context;
	
	public NorecordLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		init();
	}

	public NorecordLayout(Context context) {
		super(context);
		this.context = context;
		init();
	}
	
	private void init(){
		View view = LayoutInflater.from(context).inflate(R.layout.list_norecord, null);
		this.mainLayout = (LinearLayout)view.findViewById(R.id.norecord_mainLayout);
		this.text = (TextView)view.findViewById(R.id.norecord_text);
		this.refreshButton = (Button)view.findViewById(R.id.norecord_refershButton);
		
		mainLayout.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
			}
		});
		
		text.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		
		this.addView(view);
	}

	public Button getRefreshButton() {
		return refreshButton;
	}

	public TextView getText() {
		return text;
	}
	
	public void show(){
		this.setVisibility(View.VISIBLE);
	}
	
	public void show(int state){
		if(state==1){
			text.setText(R.string.norecord);
			refreshButton.setVisibility(View.VISIBLE);
		}else if(state==0){
			text.setText(R.string.loading_data_failure);
			refreshButton.setVisibility(View.VISIBLE);
		}
		this.setVisibility(View.VISIBLE);
	}
	
	public void hide(){
		this.setVisibility(View.GONE);
	}
	
	public void setText(String str){
		text.setText(str);
	}
	
	public void setText(int resid){
		text.setText(resid);
	}

	
}
